package org.hy.actions;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.http.converter.json.JsonR;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
/**
 * 
 * @author flexdeviser@gmail.com
 *
 */
@Controller
public class LoginAction {

	/*
	 * 注解方式创建/login.do的action方式
	 */
	/**
	 * action的普通方式
	 * @param userName
	 * @param password
	 * @return
	 */
	@RequestMapping(value = "/login")
	public ModelAndView login(@RequestParam("username") String userName,
			@RequestParam("password") String password) {
		return new ModelAndView("main.jsp", "result", "success");
	}
	
	/*
	 * 注解方式创建/login/loginAjax.do的ajax的访问方式
	 */
	/**
	 * action的ajax方式
	 * @param userName
	 * @param password
	 * @return
	 */
	@RequestMapping(value = "/login/loginAjax",method = RequestMethod.POST)
	public @ResponseBody List<Map<String,String>> loginAjax(@RequestParam("username") String userName,
			@RequestParam("password") String password) {
		
		//
		List<Map<String,String>> result = new ArrayList<Map<String,String>>();
		
		Map<String,String> info = new HashMap<String, String>();
		info.put("1", "2");
		info.put("2", "4");
		result.add(info);   
		
		//
		info = new HashMap<String, String>();
		
		info.put("1", "王海洋");
		info.put("2", "贾在波");
		result.add(info);   
		
		        
		return result;
	}

}
